// pages/myself/merchant/MerchantEntry.js
let network = null;
let utils = null;
let api = null;
const app = getApp();
var Zan = require('../../../dist/index');
let WxNotificationCenter = require('../../../utils/WxNotificationCenter.js');

Page(Object.assign({}, Zan.TopTips, {

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    network = new app.NetWorkUtils();
    utils = new app.Utils();
    api = new app.Api();

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 入进支付
   */
  goPayEnter: function (e) {
    console.log(e);
    let formId = e.detail.formId; // 可选
    let name = e.detail.value.name;
    let contacts = e.detail.value.contacts;
    let phone = e.detail.value.phone;
    let code = e.detail.value.code; // 可选
    if (name == '') {
      this.showZanTopTips(this.prompt, '请输入商家名称');
      return;
    }
    if (contacts == '') {
      this.showZanTopTips(this.prompt, '请输入联系人姓名');
      return;
    }
    if (phone == '') {
      this.showZanTopTips(this.prompt, '请输入联系人手机号');
      return;
    }
    network._post_json(this, api.addTenant, { formId: formId, name: name, contacts: contacts, phone: phone, code: code }, success);
  }
}))

// 商户入驻成功
var success = function (that, res) {
  if (res.data.data) {
    WxNotificationCenter.postNotificationName("RefreshNotification");
    app.globalData.userInfo.ccTenantId = res.data.data.id;
    wx.redirectTo({
      url: '/pages/myself/merchant/MerchantBrand',
    })
  }
}